﻿
function reload() {
    var formParam = {
    };
    $.ajax({
        type: 'post',
        url: '/System/ReloadRestIndex',
        data: formParam,
        cache: false,
        dataType: 'json',
        success: function (data) {
            if (data.success == true) {
                for (var i = 0; i < data.data.length; i++) {
                    var d = data.data[i];
                    setObj(d);
                }
            }
            else {
                //alert(data.message);
            }
        },
        error: function () {
            //alert('e');
        }
    });
}

//重新加载对象
function setObj(data) {
    var o = $("#" + data.strdivid);
    if (o == null) return;
    $(o).removeClass("tablepic0");
    $(o).removeClass("tablepic1");
    $(o).removeClass("tablepic2");
    $(o).removeClass("tablepic3");
    $(o).removeClass("tablepic4");

    $(o).addClass(data.strcss);

    $(o).find(".table-status").html(data.table_sta);

    $(o).find(".table-price").html("");
    $(o).find(".table-people").html("");

    if (data.table_status == 3 || data.table_status == 4)
    {
        $(o).find(".table-price").html("¥"+data.total_price + "元");
        $(o).find(".table-people").html("("+data.people_num + "人)");
    }
}

function load() {
    reload();
    $("#spancur").html(curdate());

    ///定时执行
    setTimeout(function () {
        load();
    }, 10000)
}

load();


function curdate() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month < 10) {
        month = '0' + month;
    }
    var day = date.getDate();
    if (day < 10) {
        day = '0' + day;
    }
    var hour = date.getHours();
    if (hour < 10) {
        hour = '0' + hour;
    }
    var minute = date.getMinutes();
    if (minute < 10) {
        minute = '0' + minute;
    }
    var second = date.getSeconds();
    if (second < 10) {
        second = '0' + second;
    }
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}



function clicktable(divid) {
    $(".actived").html("");

    $(divid).find(".actived").html("<span></span>");

    $("#hidtableid").val($(divid).find(".tableid").val());

    WinLogin("登录验证", "loginjs");
}

function loginjs(r)
{
    if (r != 1) return;
    $.ajax({
        type: 'get',
        url: '/System/GetPicInfobytableid/'+$("#hidtableid").val(),
        cache: false,
        dataType: 'json',
        success: function (data) {
            if (data.success == true) {
                var o = data.data;
                setObj(o);

                var menuid = 'actionsheetmenu' + o.table_status;
                actionSheet(menuid);
            }
            else {
                WinAlert(data.message);
                //alert(data.message);
            }
        },
        error: function () {
            WinAlert("系统异常");
        }
    });
}

///点餐
function addfood()
{
    var url = "/food/index/" + $("#hidtableid").val();
    window.location.href = url;
}


function changesta1T0() {
    var formParam = { table_id: $("#hidtableid").val() };
    $.ajax({
        type: 'post',
        url: '/System/ChangeSta1T0',
        data: formParam,
        cache: false,
        dataType: 'json',
        success: function (data) {
            if (data.success == true) {
                WinAlert("取消成功", refresh);
            }
            else {
                WinAlert(data.message);
            }
        },
        error: function () {
            WinAlert("系统异常");
        }
    });
}

function refresh()
{
    window.location.reload();
}

///加餐
function addfood1() {
    var url = "/food/AddFoodDisplay/" + $("#hidtableid").val();
    window.location.href = url;
}


///结账
function checkout() {
    var url = "/food/CheckOut/" + $("#hidtableid").val();
    window.location.href = url;
}

///订单详情
function orderdetail() {
    var url = "/food/orderdetail/" + $("#hidtableid").val();
    window.location.href = url;
}


///确认
function confirm() {
    var url = "/food/Confirm/" + $("#hidtableid").val();
    window.location.href = url;
}

///选择包厢或者大厅
function seltable(obj,type)
{
    $(".tabbable li").removeClass("active");
    $(obj).addClass("active");

    $(".tablepic").css("display","");

    $(".tablepic").each(function (index) {
        var o = $(this).find(".tabletype");
        if ($(o).val() != type)
        {
            $(this).css("display", "none");
        }

    })
}